package org.TUApp.eTour;

import android.content.Context;
import android.location.Location;
import android.widget.Toast;

import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;

public class MyLoc extends MyLocationOverlay{

	private Context mContext;
	private Location lastLoc;
	static final private float FREASH_DIST = 20.0f;  
	/**
	   private String best;
	   private LocationManager lm;
	   private Location lastLocation;
	   //the minimum time interval for notifications, in milliseconds.
	   static final private long FREASH_RATE = 15000;
	   //the minimum distance interval for notifications, in meters

	private final int mRadius = 5;
	Location location;
	public Location getLocation() {
		return location;
	}
	public void setLocation(Location location) {
		this.location = location;
	}
	
		@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		Projection projection = mapView.getProjection();
		if (shadow == false) {
			// Get the current location
			Double latitude = location.getLatitude()*1E6;
			Double longitude = location.getLongitude()*1E6;
			GeoPoint geoPoint;
			geoPoint = new
			GeoPoint(latitude.intValue(),longitude.intValue());
			// Convert the location to screen pixels
			Point point = new Point();
			projection.toPixels(geoPoint, point);
			RectF oval = new RectF(point.x - mRadius, point.y - mRadius,
			point.x + mRadius, point.y + mRadius);
			// Setup the paint
			Paint paint = new Paint();
			paint.setARGB(250, 255, 255, 255);
			paint.setAntiAlias(true);
			paint.setFakeBoldText(true);
			Paint backPaint = new Paint();
			backPaint.setARGB(175, 50, 50, 50);
			backPaint.setAntiAlias(true);
			RectF backRect = new RectF(point.x + 2 + mRadius,
			point.y - 3*mRadius,
			point.x + 65, point.y + mRadius);
			// Draw the marker
			canvas.drawOval(oval, paint);
			canvas.drawRoundRect(backRect, 5, 5, backPaint);
			canvas.drawText("Here I Am", point.x + 2*mRadius, point.y,
					paint);
		}
		super.draw(canvas, mapView, shadow);
	}
	@Override
	public boolean onTap(GeoPoint point, MapView mapView) {
		return false;
	}
*/
	public MyLoc(Context context, MapView mapView) {
		super(context, mapView);
		mContext = context;
		// TODO Auto-generated constructor stub
	}
	@Override
	public void onLocationChanged(Location location) {
		boolean needUpdate = true;
		if (lastLoc == null) 
			lastLoc = location;
		else if (lastLoc.distanceTo(location) < FREASH_DIST)
			needUpdate = false;
		if (needUpdate){
			super.onLocationChanged(location);
			lastLoc = location;
			Toast.makeText(mContext, "The current location is (lat:" + location.getLatitude() + ", lng:" + location.getLongitude(), Toast.LENGTH_LONG).show();
		}
	}
/**
	@Override
	public boolean enableMyLocation(){
//		super.enableMyLocation();
	      //register the location listener
	      //so now the 
		
	      lm = (LocationManager)mContext.getSystemService(Context.LOCATION_SERVICE);
	      Criteria criteria = new Criteria();
	      criteria.setAccuracy(Criteria.ACCURACY_FINE);
	      criteria.setAltitudeRequired(false);
	      criteria.setBearingRequired(false);
	      criteria.setCostAllowed(true);
	      criteria.setPowerRequirement(Criteria.POWER_LOW);
	      best = lm.getBestProvider(criteria, true);

	      lm.requestLocationUpdates(best, FREASH_RATE, FREASH_DIST, this);

		return true;
		
	}
	*/
	
}
